package com.liws.hellopoi.poiReadExcel;

import com.liws.hellopoi.listener.EventExample;
import com.sun.org.apache.xerces.internal.xs.datatypes.ObjectList;
import org.apache.poi.hssf.eventusermodel.HSSFEventFactory;
import org.apache.poi.hssf.eventusermodel.HSSFRequest;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;

/**
 * @Author: liweisheng
 * @Dcscription:
 * 参考文章： https://vimsky.com/examples/detail/java-method-org.apache.poi.hssf.record.NumberRecord.sid.html
 * @Date: 2022/1/28 15:39
 */
@Component
public class ExcelObject {
    private static final String Workbook = "Workbook";

    public static void readCheckbox(String path) {
        FileInputStream file = null;
        InputStream istream = null;
        try {
            file = new FileInputStream(new File(path));
            POIFSFileSystem poifs = new POIFSFileSystem(file);
            istream = poifs.createDocumentInputStream(Workbook);
            HSSFRequest req = new HSSFRequest();
            req.addListenerForAllRecords(new EventExample());
            HSSFEventFactory factory = new HSSFEventFactory();
            factory.processEvents(req, istream);

        }catch (Exception ex){
            ex.printStackTrace();
        }finally {
            try {
                if (file != null)
                    file.close();
                if (istream != null)
                    istream.close();
            }catch (IOException ex) {
                ex.printStackTrace();
            }
        }

    }


}
